/**
 *
 * Copyright Pact Lab of H.I.T.
 *
 * Designed and Implemented by Grid Researching Group, 
 * Pact Lab, Harbin
 * 
 * This Project is part of the national 973 Project:
 * Internet Based Virtual Computing Environment
 *
 * http://pact518.hit.edu.cn
 * 
 * Author:       Meteor <meteorlxk@gmail.com> 
 * Copyright:    pact518 
 * Version:      1.0
 * Created:      2009-5-6 
 * LastModified: 2009-5-6
 */
package edu.hit.pact.pgse.crawler.store;

import java.net.URL;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import edu.hit.pact.pgse.bean.RawWebPage;

/**
 * @author meteorlxk
 *
 */
public class FileSystemWebPageStore extends AbstractFileSystemStore implements WebPageStore {
	
	private boolean ifStore;
	public FileSystemWebPageStore(boolean ifStore) {
		super(LogFactory.getLog(FileSystemWebPageStore.class));
		this.ifStore = ifStore;
	}

	/* (non-Javadoc)
	 * @see edu.hit.pact.pgse.crawler.store.WebPageClient#deleteWebPage(java.net.URL)
	 */
	@Override
	public boolean deleteWebPage(URL url) {
		return deleteObject(url);
	}

	/* (non-Javadoc)
	 * @see edu.hit.pact.pgse.crawler.store.WebPageClient#loadWebPage(java.net.URL)
	 */
	@Override
	public RawWebPage loadWebPage(URL url) {
		RawWebPage property = (RawWebPage)loadObject(url);
		
		return property;
	}

	/* (non-Javadoc)
	 * @see edu.hit.pact.pgse.crawler.store.WebPageClient#storeWebPage(edu.hit.pact.pgse.bean.WebPageProperty)
	 */
	@Override
	public boolean storeWebPage(RawWebPage property) {
		if (ifStore){
			return storeObject(property.getUrlStr(), property);
		} else {
			return true;
		}
	}
	@Override
	public boolean storeWebPage(RawWebPage property,String subitem) {
		if (ifStore){
			return storeObject(property.getUrlStr(), subitem,property);
		} else {
			return true;
		}
	}
	
//	@Override
//	public boolean storeWebPage(RawWebPage property,String subitem,String pageno) {
//		logger.fatal("never used this function");
//		return false;
//	}
	
	@Override
	public boolean storeWebPage(RawWebPage property,String subitem,String pageno,boolean isOnlyText) {
		if(ifStore){
			return storeObject(property.getUrlStr(),subitem,pageno,property.getText());
		}
		return true;
	}
	
	
	
	
}
